<template>
    <div class="goods-tabs">
        <nav>
            <a :class="{ active: curr === 1 }" href="javascript:;" @click="toggle(1)">商品详情</a>
            <a :class="{ active: curr === 2 }" href="javascript:;"
                @click="toggle(2)">商品评价<span>({{evaluateCount}})</span></a>
        </nav>
        <!-- 切换内容的地方 -->
        <component :is="currComp" :product="props.product" />
    </div>
</template>

<script setup>
import { computed, ref, defineAsyncComponent } from 'vue';
const curr = ref(1)
const toggle = (val) => {
    curr.value = val
}

const currComp = computed(() => {
    if(curr.value == 1)
        return defineAsyncComponent(() => import(`./product-detail.vue`))
    else
        return defineAsyncComponent(() => import(`./product-comment.vue`))
})

const props = defineProps({
    product: Object
})

const evaluateCount = computed(() => {
    return props.product.evaluateCount ? props.product.evaluateCount+'+' : 0
})
</script>
<style lang='scss' scoped>
.goods-tabs {
    nav {
        height: 70px;
        line-height: 70px;
        display: flex;
        border-bottom: 1px solid #f5f5f5;

        a {
            padding: 0 40px;
            font-size: 18px;
            position: relative;

            >span {
                color: $priceColor;
                font-size: 16px;
                margin-left: 10px;
            }

            &:first-child {
                border-right: 1px solid #f5f5f5;
            }

            &.active {
                &::before {
                    content: "";
                    position: absolute;
                    left: 40px;
                    bottom: -1px;
                    width: 72px;
                    height: 2px;
                    background: $mainColor;
                }
            }
        }
    }
}
</style>